<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>关键词列表</title>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
</head>
<body>
<div class="layui-panel" style="padding: 8px;">
    <fieldset class="layui-elem-field layui-border-blue">
        <legend>优惠卷信息</legend>
        <form class="layui-form layui-form-pane" style="margin: 20px;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">优惠券名称</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" type="text" name="keyName" autocomplete="off" />
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <a class="layui-btn layui-btn-primary" lay-submit="" lay-filter="searchBtn">
                            <i class="layui-icon layui-icon-search"></i>
                            搜索
                        </a>
                    </div>
                </div>
            </div>
        </form>
    </fieldset>
    <div>
        <table id="keywordTable" lay-filter="keywordTable"></table>
    </div>
</div>
<!---->
<script id="tool" type="text/html">
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>
<!---->
<script id="tableBar" type="text/html">
    <a class="layui-btn layui-btn-normal layui-btn-md" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        新增
    </a>

</script>
<!---->


<script>
    var $,active;
    layui.use(['table','form','laydate','layer','dropdown','jquery'],function(){

        var table = layui.table,
            form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            dropdown = layui.dropdown;
        $ = layui.jquery;

        laydate.render({
            elem:'#endDate'
        })
        laydate.render({
            elem:'#endDate'
        })

        //加载动态表格
        table.render({

            elem:'#keywordTable',
            height:'full-160',
            page:true,
            toolbar:'#tableBar',
            url:'/keyword/kc/find',
            cols:[
                [
                    {type:'numbers',fixed:'left'},
                    {type:'checkbox',fixed:'left'},
                    {field:'id',title:'关键词ID',width:100,align: 'center'},
                    {field:'keyword',title:'关键词',width:100,align: 'center'},
                    {field:'url',title:'跳转链接',align: 'center'},
                    {field:'isHot',title:'是否推荐',width:100,align: 'center',
                        templet:function(obj){
                            var isHot = obj.isHot;
                            var str = "";
                            if(isHot == 0){
                                str = "<span style='color:#02F78E'>是</span>"
                            }else{
                                str = "<span style='color:#0080FF'>否</span>"
                            }
                            return str;
                        }
                    },
                    {field:'idDefault',title:'是否默认',width:100,align: 'center',
                        templet:function(obj){
                            var idDefault = obj.idDefault;
                            var str = "";
                            if(idDefault == 0){
                                str = "<span style='color:#02F78E'>是</span>"
                            }else{
                                str = "<span style='color:#0080FF'>否</span>"
                            }
                            return str;
                        }
                    },
                    {field:'addTime',title:'创建时间',width:300,align: 'center'},
                    {field:'updateTime',title:'更新时间',width:300,align: 'center'},
                   ,
                    {fixed:'right',title:'操作',width:180,align:'center',toolbar:'#tool'},
                ]
            ]

        });

        active = {
            addOrUpdate:function (title,content) {
                var b = false;
                top.layer.open({
                    title:title,
                    type:2,
                    content:content,
                    area:['900px','750px'],
                    btn:['确认','取消关闭'],
                    btn1:function (i,o) {
                        b = true;
                        o.find('iframe')[0].contentWindow.btnSubmit();
                    },
                    end:function (i,o) {
                        if (b) layui.table.reload('keywordTable');
                    }
                })
            },
            deleteConfirm:function (ids) {
            layer.confirm('确定删除该记录？',function (index) {
                if (index>0){
                    $.ajax({
                        type:'post',
                        url:'/keyword/kc/delete',
                        data:{
                            id:ids
                        },
                        dataType:'json',
                        success:function (result) {
                            layer.msg(result.msg);
                            if (result.is){
                                layui.table.reload('keywordTable');
                            }
                        }
                    })
                }
            });

        }
        }

        //add
        table.on('toolbar(keywordTable)',function (obj) {
            var event = obj.event;
            if ("add"==event){
                active.addOrUpdate('新增商品','/page/goods/keywordAdd');
            }
        })
        //edit
        table.on('tool(keywordTable)',function (obj) {
            var event = obj.event;
            if ("edit"==event){
                active.addOrUpdate('修改商品','/page/goods/keywordEdit/'+obj.data.id);
            } else if ('delete' == event){
                var ids = obj.data.id;
                active.deleteConfirm(ids);
            }
        })

    });

</script>


</body>
</html>